*****************************************************************************
*																			*
*								Analyse										*
*																			*
*****************************************************************************


use "alle Jahre zusammen\allyears.dta", clear
set more off 


* Umbenennungen
rename g_stdwn05 weight05
rename wei_ipf1w09 weight09
rename w_ipf1w13 weight13

rename latenz_pid_week2sd05 latenz_pid_2sdout05
rename latenz_pid_day2sd05 latenz_pid_2sddout05
rename latenz_wabs_week2sd05 latenz_wabs_2sdout05
rename latenz_wabs_day2sd05 latenz_wabs_2sddout05

foreach num in 05 09 13 {
lab var news`num' "TV-Nachrichten"
lab var internet`num' "Internet" 
}

gen week = week05 if year==2005
replace week = week09 if year==2009
replace week = week13 if year==2013
tab week year

drop if week09==-8			//zu wenige Befragte f�r 
							//wochenspezifische Analyse,
							//weil Feldzeit mittwochs begann

foreach num in 05 09 13 {
recode pidstr`num' (1/2=1) (3=2) (4=3) (5=4)
}
fre pidstr*

gen weekhelp = abs(week)
tab weekhelp

					
*------------------------------------------------------
* �bereinstimmung zwischen Wahlabsicht und PID
*-------------------------------------------------------

foreach year in 05 09 13 {
gen wabspidmatch`year' = . 
}

foreach year in 05 09 13 {
foreach num of numlist 1 4 5/7 801 {
replace wabspidmatch`year' = 1 ///
	if pid`num'`year'==1 & wabsfull`year'==`num'
replace wabspidmatch`year' = 0 ///
	if (pid`num'`year'~=1 & wabsfull`year'==`num') ///
	| (pid`num'`year'==1 & wabsfull`year'~=`num')
}
}

foreach year in 05 09 13 {
replace wabspidmatch`year' = 0 						///
	if wabsfull`year'==999 | wabsfull`year'==888	//"wei� nicht" und Nichtw�hler haben keinen Match
replace wabspidmatch`year' = . 							///
	if wabsfull`year'==. | pidunion`year'==.
lab var wabspidmatch`year' "Wahlabsicht kongruent mit PID"
}

/*
list pidunion05-pidand05 wabsfull05 wabspidmatch05 	///
	if year==2005, nolabel compress */

foreach num in 05 09 13 {
gen meanwabspidmatch`num' = .
}	

foreach num in 05 09 13 {	
	forvalues week=-10/0 {
		sum wabspidmatch`num' [aw=weight`num'] if week==`week'
		replace meanwabspidmatch`num' = r(mean) if week==`week'
	}
}


*--------------------------------------------------
* Deskriptive Kennzahlen �ber Latenzindizes
*--------------------------------------------------

* mit 2 Standardabweichungen
estimates clear
estpost sum latenz_pid*2sdout?? 
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzpidweek_2sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen PID-Latenzen (wochenweise)")


estpost sum latenz_pid*2sddout*
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzpidday_2sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen PID-Latenzen (tagesweise)")
	

estpost sum latenz_wabs*2sdout* 
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzwabsweek_2sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Wahlabsichtslatenzen (wochenweise)")

estpost sum latenz_wabs*2sddout* 
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzwabsday_2sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Wahlabsichtslatenzen (tagesweise)")


estpost sum latenz_merkel*2sdout* ///
	latenz_stein*2sdout* latenz_mip*2sdout*
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzotherweek_2sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Andere Latenzen (wochenweise)")
	
estpost sum latenz_merkel_2sddout* ///
	latenz_stein_2sddout* latenz_mip_2sddout*
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzotherday_2sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Andere Latenzen (tagesweise)")	
	
	
* mit 3 Standardabweichungen	
estimates clear
estpost sum latenz_pid_out?? 
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzpidweek_3sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen PID-Latenzen (wochenweise)")

estpost sum latenz_pid_dout*
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzpidday_3sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen PID-Latenzen (tagesweise)")
	

estpost sum latenz_wabs_out* 
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzwabsweek_3sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Wahlabsichtslatenzen (wochenweise)")

estpost sum latenz_wabs_dout* 
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzwabsday_3sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Wahlabsichtslatenzen (tagesweise)")


estpost sum latenz_merkel_out* ///
	latenz_stein_out* latenz_mip_out*
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzotherweek_3sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Andere Latenzen (wochenweise)")
	
estpost sum latenz_merkel_out* ///
	latenz_stein_out* latenz_mip_out*
esttab using "alle Jahre zusammen/Tabellen/kennzahlen_latenzotherday_3sd.rtf", ///
	cells("mean(label (Mittelwert) fmt(2)) sd(label(SD)) min(label(Min)) max(label(Max)) count(fmt(0) label(N))") ///
	noobs nonumbers replace ///
	title("Tabelle 2: Kennzahlen Andere Latenzen (tagesweise)")
		
	

*-------------------------------------------------------
* Wahlkampfdynamik Wahlabsichten
*-------------------------------------------------------

* Wahlabsichten
lookfor meanwabs 

/* 2005: 1=CDU/CSU, 2=SPD, 8=wei� nicht, 9=Nichtw�hler
2009: 1=CDU/CSU, 2=SPD, 9=wei� nicht, 10=Nichtw�hler
2013: 1=CDU/CSU, 2=SPD, 10=wei� nicht, 11=Nichtw�hler*/


graph twoway connected meanwabs105 meanwabs205 ///
	meanwabs805 meanwabspidmatch05 week05, sort ///
	ylabel(0(0.1)0.6) ///
	legend(order (4 3 1 2) ///
	label (3 "wei� nicht") ///
	label (1 "CDU/CSU") label (2 "SPD") ///
	label (4 "Kongruenz PID") ///
	position(7) ring(0) col(1)  ///
	region(lwidth(none))) scheme(s1mono) ///
	xlabel(-10(2)0) clpattern(solid solid solid solid) ///
	msymbol(O S D T) msize(large large large large) ///
	color(gs4 gs8 gs12 gs10) ///
	xtitle("") ///
	name(g2005, replace) title("2005")
	
graph twoway connected meanwabs109 meanwabs209 ///
	meanwabs909 meanwabspidmatch09 week09, sort ///
	ylabel(0(0.1)0.6) ///
	legend(off) scheme(s1mono) ///
	xlabel(-10(2)0) clpattern(solid solid solid solid) ///
	msymbol(O S D T) msize(large large large large) ///
	color(gs4 gs8 gs12 gs10) ///
	xtitle("") ///
	name(g2009, replace) title("2009")
	
graph twoway connected meanwabs113 meanwabs213 ///
	meanwabs1013 meanwabspidmatch13 week13, sort ///
	ylabel(0(0.1)0.6) ///
	legend(off) scheme(s1mono) ///
	xlabel(-10(2)0) clpattern(solid solid solid solid) ///
	msymbol(O S D T) msize(large large large large) ///
	color(gs4 gs8 gs12 gs10) ///
	xtitle("") ///
	name(g2013, replace) title("2013")
	
graph combine g2005 g2009 g2013, row(1) ///
	b1title("Wochen bis zur Bundestagswahl") ///
	scheme(s1mono)
graph export "alle Jahre zusammen/Graphiken/Wahlabsichtsdynamik.png", ///
	width(2000) height(1000) replace 

graph drop _all

*----------------------------------------------------------
* Wahlkampfdynamik politische Involvierung und Information
*-----------------------------------------------------------

* Rezeptionsvariablen alle auf wertebereich von 0 bis 1 rekodieren
foreach year in 05 09 13 {
foreach var in paper news talk {
gen `var'new`year' = `var'`year'/7
}
}

gen contactnew05 = contact_impers05/7
gen contactnew09 = contact_impers09/6
gen contactnew13 = contact_impers13/11

foreach year in 05 09 13 {
gen polintnew`year' = polint`year'/4
}

* Wchenspezifische Mittelwerte berechnen

foreach year in 05 09 13 {
foreach var in paper news talk contact polint {
gen `var'_plot`year' = .
}
}

foreach year in 05 09 13 {
foreach var in paper news talk contact polint {
forvalues num=-10/0 {
	sum `var'new`year' if week==`num' [aweight=weight`year'] 
	replace `var'_plot`year' = r(mean) if week==`num'
}
}
}

tab talk_plot13 week

foreach year in 05 09 13 {
graph twoway connected paper_plot`year' news_plot`year' talk_plot`year' ///
	contact_plot`year' polint_plot`year' week, ///
	sort name(recep`year', replace) ///
	scheme(s1mono) clpattern(solid solid solid solid solid) ///
	msymbol(S D T O Sh) lwidth(medium medium medium medium medium) ///
	msize(medium medium medium medium medium) ylabel(0(0.25)1) ///
	legend(order(1 "Zeitung" 2 "TV-Nachrichten" 3 "Gespr�che" ///
	4 "Parteikontakt" 5 "Interesse") row(2)) ///
	title("20`year'") ///
	title("20`year'") xtitle("Wochen bis zur Bundestagswahl", margin(medium))
}

grc1leg recep05 recep09 recep13, row(1) ///
	scheme(s1mono) position(6) ///
	title("Abbildung 1: Dynamik politischer Involvierung und Rezeption", ///
	size(medlarge) justification(left) position(11)) ///
	caption("Dargestellt sind Mittelwerte. Alle Variablen wurden f�r diese Darstellung auf einem Wertebereich von 0 bis 1 rekodiert." ///
	"Daten: ZA4991, ZA5303, ZA5703.", margin(medium)) 
graph export "alle Jahre zusammen/Graphiken/dynamik_reception.png", ///
	width(2000) height(1000) replace	

graph drop _all	


*---------------------------------------------------------
* Was erkl�rt die Latenzzeiten? Wochendummies
*---------------------------------------------------------

/*Mit marginsplot kann man nur die Werte aus dem letzten 
margins-Befehl plotten und nicht verschiedenen Graphiken
�bereinanderlegen ("overlay plot"). Deswegen diese
h�ndische L�sung*/

* 2005
estimates clear
foreach ding in pid wabs { 										
eststo: quietly reg latenz_`ding'_2sdout05 i.weekhelp ///
	[pweight=weight05]
	
margins, at(weekhelp=(0(1)5)) 	///
	vsquish post
	
mat t =J(6,3,.)											//erstelle Matrix mit 6 Zeilen und 3 Zeilen ohne Inhalt
mat list t

mat a = (0\-1\-2\-3\-4\-5)									//Werte �ber die Woche variieren soll
mat list a

forvalues i=1/6 { 										//�ber verlangte Anzahl Werte Woche
mat t[`i',1] = _b[`i'._at]								//get probability estimates
mat t[`i',2] = _b[`i'._at]-1.96*_se[`i'._at]			//lower bound
mat t[`i',3] = _b[`i'._at]+1.96*_se[`i'._at]			//upper bound
}

mat list t
mat t=t,a  												//Vektor a an Matrix drankleben
mat colnames t = pred_`ding'05 lci_`ding'05 			///
	uci_`ding'05 at_`ding'05

svmat t, names(col)										//aus Matrix einzelne Variable machen

mat list t
}

*2009
foreach ding in pid merkel stein mip wabs { 										
eststo: quietly reg latenz_`ding'_2sdout09 i.weekhelp ///
	[pweight=weight09]
		
margins, at(weekhelp=(0(1)7)) 	///
	vsquish post
	
mat t =J(8,3,.)											
mat list t

mat a = (0\-1\-2\-3\-4\-5\-6\-7)									

forvalues i=1/8{ 										
mat t[`i',1] = _b[`i'._at]								//get probability estimates
mat t[`i',2] = _b[`i'._at]-1.96*_se[`i'._at]			//lower bound
mat t[`i',3] = _b[`i'._at]+1.96*_se[`i'._at]			//upper bound
}

mat list t
mat t=t,a  												//Vektor a an Matrix drankleben
mat colnames t = pred_`ding'09 lci_`ding'09 			///
	uci_`ding'09 at_`ding'09

svmat t, names(col)										//aus Matrix einzelne Variable machen

mat list t
}

*2013
foreach ding in pid merkel stein wabs lire { 										
	eststo: quietly reg latenz_`ding'_2sdout13 i.weekhelp ///
	[pweight=weight13]
		
margins, at(weekhelp=(0(1)10)) 	///
	vsquish post
	
mat t =J(11,3,.)											
mat list t

mat a = (0\-1\-2\-3\-4\-5\-6\-7\-8\-9\-10)							
mat list a

forvalues i=1/11{ 										
mat t[`i',1] = _b[`i'._at]								//get probability estimates
mat t[`i',2] = _b[`i'._at]-1.96*_se[`i'._at]			//lower bound
mat t[`i',3] = _b[`i'._at]+1.96*_se[`i'._at]			//upper bound
}

mat list t
mat t=t,a  												//Vektor a an Matrix drankleben
mat colnames t = pred_`ding'13 lci_`ding'13 			///
	uci_`ding'13 at_`ding'13

svmat t, names(col)										//aus Matrix einzelne Variable machen

mat list t
}


*Graphik PID 
list at* in 1/11		//sind einfach immer die k ersten Beobachtungen im Datensatz
foreach num in 05 13 {
graph twoway (connected pred_pid`num'  			///
	at_pid13, clpattern(solid) msize(large)	///
	color(gs4)) 					///
	(line lci_pid`num' uci_pid`num' at_pid13, ///
	clpattern(dash dash) 			///
	color(gs4 gs4)), 					///
	scheme(s1mono) name(pid`num', replace) ///
	legend(off) xtitle(" ") title("20`num'") ylabel(-1(0.5)1.5)
}

foreach num in 09  {
graph twoway (connected pred_pid`num'  			///
	at_pid13, clpattern(solid) msize(large)	///
	color(gs4)) 					///
	(line lci_pid`num' uci_pid`num' at_pid13, ///
	clpattern(dash dash) 			///
	color(gs4 gs4)), 					///
	scheme(s1mono) name(pid`num', replace) ///
	legend(order(1 "PID") position(5) ring(0) region(lwidth(none))) ///
	xtitle(" ") title("20`num'") ylabel(-1(0.5)1.5)
}

graph combine pid05 pid09 pid13, ///
	ycommon row(1) scheme(s1mono) ///
	l1title("Latenz (Sekunden)") ///
	b1title("Wochen bis zur Bundestagswahl") ///
	title("Abbildung 2: Dynamik der Parteiidentifikationslatenzzeiten", ///
	size(medlarge) justification(left) position(11)) ///
	caption("Dargestellt sind vorhergesagte Werte aus einer linearer Regression der Latenzzeiten auf die Erhebungswoche" ///
	"mit 95%-Konfidenzintervall. Daten: ZA4991, ZA5303, ZA5703.", margin(medium))
graph export "alle Jahre zusammen/Graphiken/latenzpid_timedummies.png", ///
	width(2000) height(1000) replace
	
graph drop _all

* Graphik Wahlabsicht
graph twoway (connected pred_wabs09 at_wabs13, ///
	clpattern(solid) msize(large) msymbol(S) ///
	color(gs8)) ///
	(line lci_wabs09 uci_wabs09 at_wabs13, ///
	clpattern(dash dash) color(gs8 gs8)), ///
	scheme(s1mono) name(wabs09, replace) ///
	legend(order(1 "Wahlabsicht") position(5) ///
	ring(0) col(1) region(lwidth(none))) xtitle(" ") ///
	ytitle(" ") title("2009")

foreach num in 05 13 {
graph twoway (connected pred_wabs`num' ///
	at_wabs13, clpattern(solid) ///
	msize(large) ///
	color(gs8) msymbol(S)) /// 					///
	(line lci_wabs`num' uci_wabs`num' ///
	at_wabs13, clpattern(dash dash) 			///
	color(gs8 gs8)), 					///
	scheme(s1mono) name(wabs`num', replace) ///
	legend(off) xtitle(" ") title("20`num'")
}
	
graph combine wabs05 wabs09 ///
	wabs13, ycommon scheme(s1mono) ///
	b1title("Wochen bis zur Bundestagswahl") ///
	l1title("Latenz (Sekunden)") row(1) ///
	title("Abbildung 3: Dynamik der Wahlabsichtslatenzzeiten", ///
	size(medlarge) position(11) justification(left)) ///
	caption("Dargestellt sind vorhergesagte Werte aus einer linearer Regression der Latenzzeiten auf die Erhebungswoche" ///
	"mit 95%-Konfidenzintervall. Daten: ZA4991, ZA5303, ZA5703.", margin(medium))
graph export ///
	"alle Jahre zusammen/Graphiken/wabs_timedummies.png", ///
	width(2000) height(1000) replace

* Regressiontabellen
esttab est1 est3 est8 est12 est2 est7 est11 ///
	using "alle Jahre zusammen/Tabellen/reg_latenz_pidlirewabs.rtf", ///
	replace b(2) se(2) r2(2) drop(0*) ///
	mtitle("PID 2005" "PID 2009" "PID 2013" ///
	"Links-Rechts 2013" ///
	"Wahl 2005" "Wahl 2009" "Wahl 2013") ///
	order(_cons) coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	compress note("Unstandardisierte Regressionskoeffizienten mit robsuten Standardfehlern. Daten wurden gewichtet.") ///
	title("Tabelle X: Lineare Regression der Latenzzeiten auf die Erhebungwoche")

esttab est4 est5 est6 est9 est10 ///
	using "alle Jahre zusammen/Tabellen/reg_latenz_kandthemen.rtf", ///
	replace b(2) se(2) r2(2) drop(0*) ///
	mtitle("Merkel 2009" "Steinmeier 2009" ///
	"Problem 2009" "Merkel 2013" "Steinbr�ck 2013") ///
	order(_cons) coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	compress note("Unstandardisierte Regressionskoeffizienten mit robsuten Standardfehlern. Daten wurden gewichtet.") ///
	title("Tabelle X: Lineare Regression der Latenzzeiten auf die Erhebungwoche")

	
*--------------------------------------------------
* Interaktionen: Interindividuelle Variation
*---------------------------------------------------

estimates clear
foreach ding in pid wabs {
foreach num in 05 09 13 {
eststo: reg c.latenz_`ding'_2sdout`num' ///
	c.pidstr`num'##i.weekhelp [pweight=weight`num']
eststo: reg c.latenz_`ding'_2sdout`num' ///
	c.polint`num'##i.weekhelp [pweight=weight`num']	
}
}

eststo: reg latenz_lire_2sdout13 ///
		c.pidstr13##i.weekhelp [pweight=weight13]
eststo: reg latenz_lire_2sdout13 ///
		c.polint13##i.weekhelp [pweight=weight13]
	
esttab est1 est2 est3 est4 est5 est6 ///
	using "alle Jahre zusammen/Tabellen/interactions.rtf", ///
	compress b(2) se(2) r2(2) replace ///
	title("Interaktionen PID") drop(0*) ///
	coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	order(_cons 1.weekhelp 2.weekhelp 3.weekhelp ///
	4.weekhelp 5.weekhelp 6.weekhelp 7.weekhelp ///
	8.weekhelp 9.weekhelp 10.weekhelp pidstr* polint*) ///
	note("Unstandardisierte Regressionskoeffizienten mit robusten Standardfehlern. Daten wurden gewichtet.")
	
esttab est7 est8 est9 est10 est11 est12 ///
	using "alle Jahre zusammen/Tabellen/interactions.rtf", ///
	compress b(2) se(2) r2(2) append ///
	title("Interaktionen Wahlabsicht") drop(0*) ///
	coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	order(_cons 1.weekhelp 2.weekhelp 3.weekhelp ///
	4.weekhelp 5.weekhelp 6.weekhelp 7.weekhelp ///
	8.weekhelp 9.weekhelp 10.weekhelp pidstr* polint*) ///
	note("Unstandardisierte Regressionskoeffizienten mit robusten Standardfehlern. Daten wurden gewichtet.")
	
esttab est13 est14 ///
	using "alle Jahre zusammen/Tabellen/interactions.rtf", ///
	compress b(2) se(2) r2(2) append ///
	title("Interaktionen Links-Rechts-Selbsteinstufung") drop(0*) ///
	coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	order(_cons 1.weekhelp 2.weekhelp 3.weekhelp ///
	4.weekhelp 5.weekhelp 6.weekhelp 7.weekhelp ///
	8.weekhelp 9.weekhelp 10.weekhelp pidstr* polint*) ///
	note("Unstandardisierte Regressionskoeffizienten mit robusten Standardfehlern. Daten wurden gewichtet.")
		
estimates clear
eststo: reg latenz_mip_2sdout09 ///
		c.pidstr09##i.weekhelp [pweight=weight09]
eststo: reg latenz_mip_2sdout09 ///
		c.polint09##i.weekhelp [pweight=weight09]
		
foreach ding in merkel stein {
foreach num in 09 13 {
eststo: reg c.latenz_`ding'_2sdout`num' ///
	c.pidstr`num'##i.weekhelp [pweight=weight`num']
eststo: reg c.latenz_`ding'_2sdout`num' ///
	c.polint`num'##i.weekhelp [pweight=weight`num']	
}
}

esttab est1 est2		///
	using "alle Jahre zusammen/Tabellen/interactions.rtf", ///
	compress b(2) se(2) r2(2) append ///
	title("Interaktionen Wichtigstes politisches Problem") drop(0*) ///
	coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	order(_cons 1.weekhelp 2.weekhelp 3.weekhelp ///
	4.weekhelp 5.weekhelp 6.weekhelp 7.weekhelp ///
	8.weekhelp 9.weekhelp 10.weekhelp pidstr* polint*) ///
	note("Unstandardisierte Regressionskoeffizienten mit robusten Standardfehlern. Daten wurden gewichtet.")


esttab est3 est4 est5 est6 est7 est8 est9 est10 ///	
	using "alle Jahre zusammen/Tabellen/interactions.rtf", ///
	compress b(2) se(2) r2(2) append ///
	title("Interaktionen Kandidatenorientierungen") drop(0*) ///
	coeflabel(_cons "Konstante" ///
	1.weekhelp "Woche 1" 2.weekhelp "Woche 2" ///
	3.weekhelp "Woche 3" 4.weekhelp "Woche 4" ///
	5.weekhelp "Woche 5" 6.weekhelp "Woche 6" ///
	7.weekhelp "Woche 7" 8.weekhelp "Woche 8" ///
	9.weekhelp "Woche 9" 10.weekhelp "Woche 10") ///
	order(_cons 1.weekhelp 2.weekhelp 3.weekhelp ///
	4.weekhelp 5.weekhelp 6.weekhelp 7.weekhelp ///
	8.weekhelp 9.weekhelp 10.weekhelp pidstr* polint*) ///
	note("Unstandardisierte Regressionskoeffizienten mit robusten Standardfehlern. Daten wurden gewichtet.")



*------------------------------------------------------
* Einstellungs-Verhaltens-Konsistenz
*-------------------------------------------------------

*Wahlabsicht
estimates clear
foreach num in 05 09 13 {
eststo: quietly logit wabspidmatch`num'  ///
	c.latenz_pid_2sdout`num' pidstr`num' ///
	polint`num' ///
	[pweight=weight`num'] if pidno`num'==0 
sum latenz_pid_2sdout`num' if e(sample)
local a = round(r(min))
local b = round(r(max))
margins, at(c.latenz_pid_2sdout`num'=(`a'(1)`b')) ///
	asobserved 
marginsplot, scheme(s1mono) recastci(rline) ///
	ciopts(lpattern(dash)) ///
	name(wabspidmatch`num', replace) ///
	title("20`num'") xlabel(`a' 0 `b') ///
	xtitle("") ///
	ytitle("") ylabel(0.3(0.1)0.8)
}

graph combine wabspidmatch05 wabspidmatch09 ///
	wabspidmatch13, scheme(s1mono) row(1) ///
	b1title("Latenz Parteiidenpngikation") ///
	l1title("P(Wahl=Parteiidenpngikation)")  ///
	note("Vorhergesagte Wahrscheinlichkeiten aus logistischer Regression mit 95%-Konfidenzintervall.", margin(medium))
graph export "alle Jahre zusammen/Graphiken/wabspidmatch.png", width(2000) ///
	height(1000) replace
	
esttab using "alle Jahre zusammen/Tabellen/wabspidmatch.rtf", ///
	replace mtitles("2005" "2009" "2013") nonumbers ///
	eqlabels(none) b(2) se(2) pr2(2) label ///
	title("Tabelle X: Zug�nglichkeit als Moderator der Einstellungs-Verhaltens-Konsistenz?" ///
	"Logistische Regression der �bereinstimmung zwischen Parteiidenpngikation und Wahlabsicht")

* Tats�chliches Wahlverhalten
estimates clear	
foreach num in 05 09 13 {
eststo: quietly logit votepidmatch`num'  ///
	c.latenz_pid_2sdout`num' pidstr`num' ///
	polint`num' ///
	[pweight=weight`num'] if pidno`num'==0 
sum latenz_pid_2sdout`num' if e(sample)
local a = round(r(min))
local b = round(r(max))
margins, at(c.latenz_pid_2sdout`num'=(`a'(1)`b')) ///
	asobserved 
marginsplot, scheme(s1mono) recastci(rline) ///
	ciopts(lpattern(dash)) ///
	name(votepidmatch`num', replace) ///
	title("20`num'") xlabel(`a' 0 `b') ///
	xtitle("") ///
	ytitle("") ylabel(0(0.1)0.8)
}

graph combine votepidmatch05 votepidmatch09 ///
	votepidmatch13, scheme(s1mono) row(1) ///
	b1title("Latenz Parteiidentifikation") ///
	l1title("P(Wahl=Parteiidentifikation)") ///
	title("Abbildung 4: Einfluss der Parteiidentifikationszug�nglichkeit auf die Einstellungs-Verhaltens-Konsistenz", ///
	size(medlarge) justification(left) position(11)) ///
	caption("Vorhergesagte Wahrscheinlichkeiten aus logistischer Regression mit 95%-Konfidenzintervall." ///
	"Daten: ZA4991, ZA5303, ZA5703.", margin(medium))
graph export "alle Jahre zusammen/Graphiken/votepidmatch.png", width(2000) ///
	height(1000) replace

esttab est1 est2 est3 using "alle Jahre zusammen/Tabellen/votepidmatch.rtf", ///
	replace  nonumbers ///
	mtitles("2005" "2009" "2013") ///
	eqlabels(none) b(2) se(2) pr2(2) label ///
	coeflabel(latenz_pid_2sdout05 "Latenz PID" ///
	latenz_pid_2sdout09 "Latenz PID" ///
	latenz_pid_2sdout13 "Latenz PID" ///
	_cons "Konstante") /// 
	order(_cons latenz_pid_2sdout05 latenz_pid_2sdout09 ///
	latenz_pid_2sdout13 pidstr05 pidstr09 pidstr13 ///
	polint05 polint09 polint13)  ///
	title("Tabelle X: Zug�nglichkeit als Moderator der Einstellungs-Verhaltens-Konsistenz?" ///
	"Logistische Regression der �bereinstimmung zwischen Parteiidenpngikation und Wahlabsicht") ///
	note("Unstandardisierte Regressionskoeffizienten mit robusten Standardfehlern.")

graph drop _all

